package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.utlis.Aes;
import com.ymk.bo.user.SopUserBO;
import com.ymk.core.code.cmd.UserCmdCode;
import com.ymk.core.enums.mch.MchUserStatusEnum;
import com.ymk.service.ISopUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class SopUserPostCmd extends ACmd {

    @Override
    public CmdSign executeSop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        SopUserBO sopUserBO = super.getData(sign, SopUserBO.class);

        String salt = Aes.creatSalt();
        sopUserBO.setSalt(salt);
        sopUserBO.setPassword(Aes.getMD5(sopUserBO.getPassword(), salt));
        sopUserBO.setStatus(MchUserStatusEnum.NORMAL.getStatus());
        super.setCreatedData(sign,sopUserBO);

        this.sopUserService.post(sopUserBO);

        return respSign;
    }

    @Override
    public boolean anon(CmdSign sign) {
        return true;
    }

    @Override
    public String getCmdCode() {
        return UserCmdCode.SOP_USER_POST;
    }

    @Autowired
    private ISopUserService sopUserService;
}